Skip to content

Add file upload support for chat sessions (#19)#61

Merged
cnu1812 merged 9 commits intojenkinsci:mainfrom
GunaPalanivel:feature/19-file-upload-support
Dec 26, 2025
Merged

Add file upload support for chat sessions (#19)#61
cnu1812 merged 9 commits intojenkinsci:mainfrom
GunaPalanivel:feature/19-file-upload-support

Conversation

@GunaPalanivel
Copy link
Copy Markdown
Contributor

Summary

Adds the ability for users to attach files when sending messages to the chatbot, giving the LLM richer context for troubleshooting Jenkins issues.

Changes

Backend (Python/FastAPI)

  • New file_service.py module for file processing and validation
  • Added multipart form upload endpoint POST /sessions/{session_id}/message/upload
  • Added GET /files/supported-extensions endpoint for frontend validation
  • Updated chat_service.py to incorporate file content into LLM prompts
  • New Pydantic models: FileAttachment, ChatRequestWithFiles, SupportedExtensionsResponse

Frontend (React/TypeScript)

  • Added attach button (📎) to the input component
  • File preview chips showing name, size, and remove option
  • Image thumbnails and file icons displayed in chat messages
  • Client-side validation for file size and extension

Supported File Types

  • Logs/Text: .txt, .log, .md
  • Code: .py, .js, .ts, .tsx, .java, .groovy, .sh
  • Config: .json, .xml, .yaml, .yml, .properties, .toml
  • Jenkins: Jenkinsfile, .groovy
  • Images: .png, .jpg, .jpeg, .gif, .webp, .bmp

Limits

  • Max file size: 10MB per file
  • Images are base64 encoded for LLM vision capabilities

Testing

  • Added unit tests for file service (test_file_service.py)
  • Added route tests for upload endpoint (test_file_upload.py)
  • Updated frontend tests for Input component

How to Test

  1. Start the backend and frontend servers
  2. Click the 📎 button or drag files into the input area
  3. Attach a log file or screenshot and ask a question
  4. Verify the file content appears in the chat and the LLM references it

Closes #19

- Add file_service.py for processing uploaded files (text extraction, validation)
- Support 30+ file types including logs, code files, configs, and images
- Add multipart upload endpoint POST /sessions/{id}/message/upload
- Add GET /files/supported-extensions endpoint
- Update frontend with attach button, file preview chips, and drag-drop ready UI
- Display image thumbnails and file icons in chat messages
- Add file size validation (10MB limit) and extension checks
- Include unit tests for file service and upload routes
@GunaPalanivel GunaPalanivel requested a review from a team as a code owner December 17, 2025 13:52
Comment thread chatbot-core/api/models/schemas.py
Comment thread chatbot-core/api/models/schemas.py Outdated
Comment thread chatbot-core/api/services/chat_service.py
Comment thread chatbot-core/api/services/file_service.py Outdated
Comment thread chatbot-core/tests/unit/routes/test_file_upload.py
Comment thread chatbot-core/tests/unit/routes/test_file_upload.py
Comment thread chatbot-core/tests/unit/services/test_file_service.py
Comment thread frontend/src/tests/Input.test.tsx Outdated
Comment thread frontend/src/tests/Input.test.tsx
Comment thread frontend/src/tests/Input.test.tsx
@cnu1812
Copy link
Copy Markdown
Member

cnu1812 commented Dec 17, 2025

Also, a few checks are failing. Take a note!

- Add python-multipart dependency for form data support
- Use FileType Enum instead of string for type field (schemas.py)
- Add proper model_validator for message/files validation (schemas.py)
- Use XML-style tags for robust file context formatting (file_service.py)
- Handle hidden files (.env, .gitignore, etc.) as text files
- Add 'raise ... from e' pattern for exception chaining (chatbot.py)
- Close uploaded files in finally block (chatbot.py)
- Remove trailing whitespace and fix line length issues
- Remove unused imports (Optional, pytest, TestClient)
- Add tests for file size limit enforcement
- Add tests for text truncation
- Add tests for hidden files support
- Add tests for file input trigger callback
- Add whitespace-only negative case test
- Use data-testid instead of emoji for file icons
- Add missing mocks in Chatbot.test.tsx (fetchSupportedExtensions, etc.)
@GunaPalanivel
Copy link
Copy Markdown
Contributor Author

Also, a few checks are failing. Take a note!

CI Failures Fixed

Backend Tests Failure

Form data requires "python-multipart" to be installed.

Resolution: Added python-multipart==0.0.20 to requirements.txt


Frontend Tests Failure

TypeError: (0 , chatbot_1.fetchSupportedExtensions) is not a function

Resolution: Added missing mocks in Chatbot.test.tsx:

jest.mock("../api/chatbot", () => ({
  fetchChatbotReply: jest.fn()...,
  fetchChatbotReplyWithFiles: jest.fn()...,
  fetchSupportedExtensions: jest.fn().mockResolvedValue({...}),
  validateFile: jest.fn().mockReturnValue({ isValid: true }),
  fileToAttachment: jest.fn()...,
  // ... other mocks
}));

Pylint Failures

Fixed all pylint issues:

  • Trailing whitespace (C0303)
  • Line too long (C0301)
  • Unused imports (W0611)
  • raise-missing-from (W0707)
  • Unnecessary pass statement (W0107)
  • Wrong import order (C0411)

…orrect data

- Added mock_get_chatbot_reply.assert_called_once() assertions
- Verify filename and content are correctly passed to service
- Check multiple files are all processed correctly
- Verify truncation logic works by checking content length
Comment thread chatbot-core/api/services/file_service.py
Comment thread chatbot-core/api/services/file_service.py
Comment thread chatbot-core/api/services/file_service.py Outdated
Copy link
Copy Markdown
Contributor

@berviantoleo berviantoleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comments. Some of them are required changes to strengthen the validation.

- Add python-magic for MIME type detection from content
- Implement detect_mime_type_from_content() with fallback signatures
- Add validate_file_content_type() to verify content matches extension
- Block executables disguised as text files
- Reject images with mismatched content/extension
- Add comprehensive unit tests for new validation functions
@berviantoleo
Copy link
Copy Markdown
Contributor

Please have a look at the failed CIs

GunaPalanivel and others added 2 commits December 19, 2025 12:12
…matting

- Prioritize our magic byte signatures over python-magic for images
- This ensures consistent behavior across different environments
- Fix pylint unused-argument warning in test_file_upload.py
- Fix broad-exception-caught by catching specific exceptions
- Run prettier to fix frontend formatting issues
- Update test for unknown content detection
@berviantoleo berviantoleo added the enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted label Dec 22, 2025
@GunaPalanivel GunaPalanivel force-pushed the feature/19-file-upload-support branch from d8bf116 to d163334 Compare December 22, 2025 14:01
@GunaPalanivel
Copy link
Copy Markdown
Contributor Author

Hey @berviantoleo, thanks for the review! We’ve been hitting some stubborn CI fails—mostly due to PyTorch and CUDA version conflicts on the latest Python. Our plan is to relax the strict version pins and let pip resolve the right dependencies, following PyTorch’s official guidance. If you’re good with this approach, we’ll go ahead and update the requirements accordingly. Let us know your thoughts!

@berviantoleo
Copy link
Copy Markdown
Contributor

berviantoleo commented Dec 22, 2025

Hey @berviantoleo, thanks for the review! We’ve been hitting some stubborn CI fails—mostly due to PyTorch and CUDA version conflicts on the latest Python. Our plan is to relax the strict version pins and let pip resolve the right dependencies, following PyTorch’s official guidance. If you’re good with this approach, we’ll go ahead and update the requirements accordingly. Let us know your thoughts!

Good to go. However, @GunaPalanivel, please focusing to fix 3.12 and 3.13. I'm just experimenting with 3.14, so you can ignore the install dependencies error at the moment.

@GunaPalanivel
Copy link
Copy Markdown
Contributor Author

GunaPalanivel commented Dec 24, 2025

@berviantoleo Done.

@GunaPalanivel GunaPalanivel force-pushed the feature/19-file-upload-support branch from 88a97e8 to d163334 Compare December 24, 2025 14:09
@cnu1812 cnu1812 merged commit 1fc36ef into jenkinsci:main Dec 26, 2025
34 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for file uploading

3 participants